#ifndef _YINTEGER_H
#define _YINTEGER_H
#include <tool/ydefine.h>

/** Function pointers struct, use externally */
typedef struct intFn *intFn;
/** Data struct, use internally */
typedef struct intFnData *intFnData;

/** integer struct of function pointers */
struct intFn {
  /*--- data ---*/
  intFnData d;
  /*--- function pointers ---*/
  /** Free a intFn, free up the memory.
  @param fnP pass in the address of <code>intFn</code> to be free.
  @return <code>true</code> if successfully otherwise <code>false</code>.
  */
  boolean (*freeFn)(intFn *fnP);
  /*--- integer to string conversion */
  /** Convert an unsigned char number to string.
  <p>Since this string is <code>malloc(..)</code>, to avoid memory leak
  it should be freed when no longer needed with a call to 
  <code>free(void *)</code>.
  </p>
  @param fn the <code>intFn</code> object to use.
  @param num the unsigned char number.
  @return a string if successful otherwise <code>NULL</code> if failure.
  */
  char *(*unsignedCharNumToStr)(
      const intFn fn, const unsigned char num);
  /** Convert a char number to string.
  <p>Since this string is <code>malloc(..)</code>, to avoid memory leak
  it should be freed when no longer needed with a call to 
  <code>free(void *)</code>.
  </p>
  @param fn the <code>intFn</code> object to use.
  @param num the char number.
  @return a string if successful otherwise <code>NULL</code> if failure.
  */
  char *(*charNumToStr)(const intFn fn, const char num);
  /** Convert an unsigned int number to string.
  <p>Since this string is <code>malloc(..)</code>, to avoid memory leak
  it should be freed when no longer needed with a call to 
  <code>free(void *)</code>.
  </p>
  @param fn the <code>intFn</code> object to use.
  @param num the unsigned int number.
  @return a string if successful otherwise <code>NULL</code> if failure.
  */
  char *(*unsignedIntNumToStr)(
      const intFn fn, const unsigned int num);
  /** Convert an short int number to string.
  <p>Since this string is <code>malloc(..)</code>, to avoid memory leak
  it should be freed when no longer needed with a call to 
  <code>free(void *)</code>.
  </p>
  @param fn the <code>intFn</code> object to use.
  @param num the short int number.
  @return a string if successful otherwise <code>NULL</code> if failure.
  */
  char *(*shortIntNumToStr)(const intFn fn, const short int num);
  /** Convert an int number to string.
  <p>Since this string is <code>malloc(..)</code>, to avoid memory leak
  it should be freed when no longer needed with a call to 
  <code>free(void *)</code>.
  </p>
  @param fn the <code>intFn</code> object to use.
  @param num the int number.
  @return a string if successful otherwise <code>NULL</code> if failure.
  */
  char *(*intNumToStr)(const intFn fn, const int num);
  /** Convert an unsigned long number to string.
  <p>Since this string is <code>malloc(..)</code>, to avoid memory leak
  it should be freed when no longer needed with a call to 
  <code>free(void *)</code>.
  </p>
  @param fn the <code>intFn</code> object to use.
  @param num the unsigned long number.
  @return a string if successful otherwise <code>NULL</code> if failure.
  */
  char *(*unsignedLongNumToStr)(
      const intFn fn, const unsigned long num);
  /** Convert an long number to string.
  <p>Since this string is <code>malloc(..)</code>, to avoid memory leak
  it should be freed when no longer needed with a call to 
  <code>free(void *)</code>.
  </p>
  @param fn the <code>intFn</code> object to use.
  @param num the long number.
  @return a string if successful otherwise <code>NULL</code> if failure.
  */
  char *(*longNumToStr)(const intFn fn, const long num);
  /*--- cloning */
  /** Duplicate an unsigned int array.
  <p>Since this array is <code>malloc(..)</code>, to avoid memory leak
  it should be freed when no longer needed with a call to 
  <code>free(void *)</code>.
  </p>
  @param fn the <code>intFn</code> to use.
  @param array the array
  @param len the length of the array
  @return new string or <code>NULL</code> if unsuccessful.
  */
  size_t *(*cloneUnsignedIntArray)(const intFn fn, 
      const size_t *array, size_t len);
};

/** Create a <code>intFn</code> that provide 
the struct of integer function pointers.
@return a working struct of integer function pointers.
  or <code>NULL</code> if failure.
*/
intFn yinteger_createFn(void);

#endif /* _YINTEGER_H */
